/**
 * 创元汇 - WebName
 * https://menger.me
 * @大梦
 */

import React, {Component} from 'react'
import {
    Text,
    View,
    Image,
    Modal,
    WebView,
    Linking,
    Platform,
    TextInput,
    StatusBar,
    ScrollView,
    StyleSheet,
    RefreshControl,
    TouchableOpacity,
} from 'react-native'

import ScrollableTabView, {DefaultTabBar,ScrollableTabBar} from 'react-native-scrollable-tab-view'
import { StackActions, NavigationActions } from 'react-navigation'

import NetRequest from '../../utils/utilsRequest'
import CheckVersion from '../../utils/CheckVersion'
import ServicesApi from '../../constants/ServicesApi'
import GlobalStyles from '../../constants/GlobalStyles'
import NavigationBar from '../../components/common/NavigationBar'
import UtilsView from '../../utils/utilsView'
import { toastShort, toastLong, consoleLog } from '../../utils/utilsToast'
import Video from 'react-native-video';
import BannerView from '../../components/common/Banner'
import AlertManager from '../../components/common/AlertManager'
import {Overlay, Label, Button} from 'teaset'

export default class Home extends Component {

    constructor(props) {
        super(props);
        this.state =  {
            homeData: [],
            about_us: [],
            fund: [],
            article: [],
            notice: [],
            banner: [],
            loginState: false,
            videoSource: '',
            isPlay: false,
            modalVisible: false,
            isRefreshing: false,
            upup: 0,
            appname: '创金财富',
            mobile: '',
            user_services_link: '',
            privacy_policy_link: '',
            user_services_title: '《用户服务协议》',
            privacy_policy_title: '《隐私政策协议》',
        }
        // this.netRequest = new NetRequest();
        this.props.navigation.addListener('willFocus', this.componentWillFocus);

        
    }

    async componentWillMount(){
        try {
            let result = await storage.load({key: 'loginState'});
            console.log('global.user---->', global.user);
            console.log('result---->', result);
            // this._requestUserInfo(result.id, result.token);
        } catch (error) {
            // console.log(error);
        }
    }

    componentWillFocus = () => {
        console.log('componentWillFocus---->', 'componentWillFocus');
        global.user && global.user.loginState && this._requestUserInfo(global.user.userData.id, global.user.userData.token);
    }

    componentDidMount(){
        this._requestDataSources();
        this._checkVersionUpdate();
        this._loadLocalStatus();
    }

    _onRefresh = async () => {
        this.setState({isRefreshing: true});
        this._requestDataSources();
        this._checkVersionUpdate();
        setTimeout(() => this.setState({isRefreshing: false}), 200);
    };

    componentWillUnmount(){
        
    }

    onBack = () => {
        this.props.navigation.goBack();
    }

    updateState= (state) => {
        if (!this) { return };
        this.setState(state);
    }

    // 检查版本更新
    _checkVersionUpdate = async () => {
        CheckVersion();
    };

    
    
    // 请求首页数据
    _requestDataSources = async () => {
        let url = ServicesApi.home;
        let data = {
            version_name: Constants.VERSION_NAME,
            version_code: Constants.VERSION_CODE,
        };
        try {
            let result = await Services.post(url, data, true);
            if(result && result.code == StatusCode.SUCCESS_CODE){
                this.updateState({
                    homeData: result.data,
                    fund: result.data.fund,
                    notice: result.data.notice,
                    banner: result.data.banner,
                    article: result.data.article,
                    about_us: result.data.about_us,
                    videoSource: result.data.video,
                });
            }
        } catch (error) {
            // consoleLog('链接服务器出错，请稍后重试', error);
        }    
    }

    /**
     * 获取用户信息
     * @param member_id [global.user.userData.id]
     * @param token [global.user.userData.token]
     **/
    _requestUserInfo = (member_id, token) => {
        let url = ServicesApi.get_member_info;
        let data = {
            token,
            member_id,
        };
        Services.post(url, data, true)
            .then( result => {
                console.log(result);
                if (result && result.code == StatusCode.SUCCESS_CODE) {
                    let user = result.data;

                    storage.save({
                        key: 'loginState',
                        data: user
                    });

                    global.user = {
                        loginState: true,
                        userData: user
                    };

                    this.updateState({
                        upup: 1
                    });

                }else{
                    storage.remove({
                        key: 'loginState',
                    });
                    global.user.loginState = false;
                    global.user.userData = [];
                    setTimeout(() => {
                        toastShort('您的账户信息已过期，请重新登录！')
                        const resetAction = NavigationActions.reset({
                            index: 0,
                            actions: [
                                NavigationActions.navigate({ routeName: 'Login'})
                            ]
                        })
                        this.props.navigation.dispatch(resetAction)
                    }, 101)
                }
            })
            .catch( error => {
                // toastShort('服务器请求失败，请稍后重试！');
            })
    }

    videoPlay = () => {
        this.updateState({
            isPlay: !this.state.isPlay
        })
    }

    onPushNavigator = (compent) => {
        const { navigate } = this.props.navigation;
        navigate( compent , {
            onCallBack:()=>{
                console.log('1');
            }
        })
    }

    onPushToFundDetail = (compent, fund_id, title, datum_rate, buy_end_day, buy_end_money, time_limit, start_buy_money, end_people, is_collection) => {
        const { navigate } = this.props.navigation;
        navigate( compent , {
            fund_id: fund_id,
            title: title,
            datum_rate: datum_rate,
            buy_end_day: buy_end_day,
            buy_end_money: buy_end_money,
            time_limit: time_limit,
            start_buy_money: start_buy_money,
            end_people: end_people,
            is_collection: is_collection,
            onCallBack:()=>{
                this._requestUserInfo(global.user.userData.id, global.user.userData.token);
            }
        })
    }

    toWebview = (title, link, compent, id) => {
        const { navigate } = this.props.navigation;
        navigate(compent, {
            title: title,
            link: link,
            id: id,
        })
    }

    _onPressAlert1 = () => {
        const params = {
            title: '温馨提示',
            detail: '尊敬的会员，根据基金业协会管理规定，查阅基金产品信息请先完成特定对象认定程序，点击”同意“进入特定对象认定开始风险测评，点击“暂不”，返回系统首页。',
            actions: [
                { title: '暂不', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                    
                } },
                { title: '同意', onPress: () => { 
                    this.onPushNavigator('PingguLogin');
                } }
            ]
        }
        AlertManager.show(params)
    }

    _onPressAlert2 = () => {
        const params = {
            title: '温馨提示',
            detail: '尊敬的会员，根据基金业协会管理规定，查阅基金产品信息请先完成特定对象认定程序，系统检测到您已完成风险测评，点击“继续”进行风险测评问卷的签署',
            actions: [
                { title: '暂不', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                    
                } },
                { title: '继续', onPress: () => { 
                    let url = ServicesApi.get_url_001;

                    let data = {
                        member_id: global.user.userData.id,
                        token: global.user.userData.token,
                    }
        
                    Services.post(url, data, true)
                        .then( result => {
                            console.log(result);
                            this.pingguAgree(result.data.url, result.data.show_url);
                        })
                        .catch( error => {
                            // consoleLog('链接服务器出错，请稍后重试', error);
                        })
                    
                } }
            ]
        }
        AlertManager.show(params)
    }

    pingguAgree = (shuju, show_link) => {
        let overlayView = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView && this.overlayView.close()}} style={styles.botLeft}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.submit001(shuju);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意签署</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView);
    }

    submit001 = (shuju) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: shuju,
            style: '001',
            id: '',
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
            .then( result => {
                console.log(result);
                // 关闭浮层
                AlertManager.hide();
                if (result && result.code == StatusCode.SUCCESS_CODE) {
                    const params = {
                        title: '温馨提示',
                        detail: '尊敬的会员，您已成功签署风险测评问卷，请点击“继续”，进行签署《符合合格投资者标准的承诺书》。',
                        actions: [
                            { title: '暂不', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                                this.overlayView && this.overlayView.close()
                                this._requestUserInfo(global.user.userData.id, global.user.userData.token);
                            } },
                            { title: '继续', onPress: () => { 
                                this.overlayView && this.overlayView.close()
                                this.onPushNavigator('RenzhengchengnuoLogin');
                            } }
                        ]
                    }
                    AlertManager.show(params)
                }else{
                    toastLong(result.msg);
                }
            })
            .catch( error => {
                // toastShort('服务器请求失败，请稍后重试！');
            })
    }

    _onPressAlert3 = () => {
        const params = {
            title: '温馨提示',
            detail: '尊敬的会员，根据基金业协会管理规定，查阅基金产品信息请先完成特定对象认定程序，系统检测到您已成功签署风险测评问卷，请点击“继续”，进行签署《符合合格投资者标准的承诺书》',
            actions: [
                { title: '暂不', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                    
                } },
                { title: '继续', onPress: () => { 
                    this.onPushNavigator('RenzhengchengnuoLogin');
                } }
            ]
        }
        AlertManager.show(params)
    }

    _onPressAlert4 = () => {
        const params = {
            title: '温馨提示',
            detail: '尊敬的会员，根据基金业协会管理规定，查阅基金产品信息请先完成特定对象认定程序，系统检测到您已成功签署《符合合格投资者标准的承诺书》，请点击“继续”，进行签署《投资者风险匹配告知书及投资者确认函》。',
            actions: [
                { title: '暂不', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                    
                } },
                { title: '继续', onPress: () => { 
                    let url = ServicesApi.get_url_003;

                    let data = {
                        member_id: global.user.userData.id,
                        token: global.user.userData.token,
                    }
        
                    Services.post(url, data, true)
                        .then( result => {
                            console.log(result);
                            this.pingguAgree003(result.data.url, result.data.show_url);
                        })
                        .catch( error => {
                            // consoleLog('链接服务器出错，请稍后重试', error);
                        })
                } }
            ]
        }
        AlertManager.show(params)
    }

    pingguAgree003 = (shuju, show_link) => {
        let overlayView = (
            <Overlay.PullView side='bottom' modal={false} ref={v => this.overlayView = v}>
                <View style={{backgroundColor: '#fff', width: GlobalStyles.width, height: GlobalStyles.height}}>
                    <WebView
                        startInLoadingState={true}
                        source={{uri: show_link}}
                        style={styles.webContainer}
                    />
                    
                    <View style={styles.botBar}>
                        <TouchableOpacity onPress={()=>{this.overlayView && this.overlayView.close()}} style={styles.botLeft}>
                            <Text style={[styles.botLeftText, {fontSize: 15}]}>取消</Text>
                        </TouchableOpacity>
                        <TouchableOpacity onPress={()=>{this.submit003(shuju);}} style={styles.botRight}>
                            <Text style={styles.botRightText}>同意签署</Text>
                        </TouchableOpacity> 
                    </View>
                </View>
            </Overlay.PullView>
        );
        Overlay.show(overlayView);
    }

    submit003 = (shuju) => {
        let url = ServicesApi.create_pdf;
        let data = {
            url: shuju,
            style: '003',
            id: '',
            member_id: global.user.userData.id,
            token: global.user.userData.token,
        }
        AlertManager.showPopView(<View style={[GlobalStyles.loadingview, GlobalStyles.flexColumnCenter]}><Image source={require('../../assets/images/icons/loading.gif')} style={GlobalStyles.loading} /><Text style={GlobalStyles.loadingtext}>文件生成中，请稍候...</Text></View>, { modal:true })
        Services.post(url, data, true)
        .then( result => {
            console.log(result);
            AlertManager.hide();
            if (result && result.code == StatusCode.SUCCESS_CODE) {
                if(global.user.userData.is_investor == 0 || global.user.userData.is_investor == -2){
                    const params = {
                        title: '温馨提示',
                        detail: '尊敬的会员，您已成功签署本承诺书，并恭喜完成特定对象认定，点击“继续”，进入专业投资者认定（阅读风险揭示书），点击“返回”，返回基金频道查看基金产品信息。',
                        actions: [
                            { title: '返回', titleStyle: {  }, actionStyle: {  }, onPress: () => { 
                                this.overlayView && this.overlayView.close()
                                this._requestUserInfo(global.user.userData.id, global.user.userData.token);
                            } },
                            { title: '继续', onPress: () => { 
                                this.overlayView && this.overlayView.close()
                                this.onPushNavigator('RenzhengTypeLogin');
                            } }
                        ]
                    }
                    AlertManager.show(params)
                }else {
                    this.overlayView && this.overlayView.close()
                }
            }else{
                toastLong(result.msg);
            }
        })
        .catch( error => {
            // toastShort('服务器请求失败，请稍后重试！');
        })
    }

    homeFund(data) {
        if(!global.user.loginState){
            if(data.length > 0){
                let fundList = [];
                for (var i = 0; i < data.length; i++) {
                    let fundItem = (
                        <TouchableOpacity key={i} onPress={()=>{this.onPushToFundDetail('Login')}} style={GlobalStyles.fundList}>
                            <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                <Image source={require('../../assets/images/images/image_index_mohu1.png')} style={GlobalStyles.fundMohu1} />
                            </View>
                            <View style={GlobalStyles.fundMid}>
                                <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                            </View>
                            <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                <Image source={require('../../assets/images/images/image_index_mohu.png')} style={GlobalStyles.fundMohu} />
                            </View>
                        </TouchableOpacity>
                    )
                    fundList.push(fundItem);
                }
                return (
                    <View style={GlobalStyles.fundModule}>
                        {fundList}
                    </View>
                );
            }else {
                return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
            }    
        }else if(global.user.loginState){
            if(global.user.userData.is_risk == 0){
                if(global.user.userData.is_risk_answer == 0){
                    if(data.length > 0){
                        let fundList = [];
                        for (var i = 0; i < data.length; i++) {
                            let fundItem = (
                                <TouchableOpacity key={i} onPress={()=>{this._onPressAlert1();}} style={GlobalStyles.fundList}>
                                    <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                        <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                        <Image source={require('../../assets/images/images/image_index_mohu1.png')} style={GlobalStyles.fundMohu1} />
                                    </View>
                                    <View style={GlobalStyles.fundMid}>
                                        <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                                    </View>
                                    <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                        <Image source={require('../../assets/images/images/image_index_mohu.png')} style={GlobalStyles.fundMohu} />
                                    </View>
                                </TouchableOpacity>
                            )
                            fundList.push(fundItem);
                        }
                        return (
                            <View style={GlobalStyles.fundModule}>
                                {fundList}
                            </View>
                        );
                    }else {
                        return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
                    }   
                }else{
                    if(global.user.userData.new_status == 0){
                        if(data.length > 0){
                            let fundList = [];
                            for (var i = 0; i < data.length; i++) {
                                let fundItem = (
                                    <TouchableOpacity key={i} onPress={()=>{this._onPressAlert2();}} style={GlobalStyles.fundList}>
                                        <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                            <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                            <Image source={require('../../assets/images/images/image_index_mohu1.png')} style={GlobalStyles.fundMohu1} />
                                        </View>
                                        <View style={GlobalStyles.fundMid}>
                                            <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                                        </View>
                                        <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                            <Image source={require('../../assets/images/images/image_index_mohu.png')} style={GlobalStyles.fundMohu} />
                                        </View>
                                    </TouchableOpacity>
                                )
                                fundList.push(fundItem);
                            }
                            return (
                                <View style={GlobalStyles.fundModule}>
                                    {fundList}
                                </View>
                            );
                        }else {
                            return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
                        } 
                    }else if(global.user.userData.new_status == 1){
                        if(data.length > 0){
                            let fundList = [];
                            for (var i = 0; i < data.length; i++) {
                                let fundItem = (
                                    <TouchableOpacity key={i} onPress={()=>{this._onPressAlert3();}} style={GlobalStyles.fundList}>
                                        <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                            <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                            <Image source={require('../../assets/images/images/image_index_mohu1.png')} style={GlobalStyles.fundMohu1} />
                                        </View>
                                        <View style={GlobalStyles.fundMid}>
                                            <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                                        </View>
                                        <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                            <Image source={require('../../assets/images/images/image_index_mohu.png')} style={GlobalStyles.fundMohu} />
                                        </View>
                                    </TouchableOpacity>
                                )
                                fundList.push(fundItem);
                            }
                            return (
                                <View style={GlobalStyles.fundModule}>
                                    {fundList}
                                </View>
                            );
                        }else {
                            return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
                        } 
                    }else if(global.user.userData.new_status == 2){
                        if(data.length > 0){
                            let fundList = [];
                            for (var i = 0; i < data.length; i++) {
                                let fundItem = (
                                    <TouchableOpacity key={i} onPress={()=>{this._onPressAlert4();}} style={GlobalStyles.fundList}>
                                        <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                            <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                            <Image source={require('../../assets/images/images/image_index_mohu1.png')} style={GlobalStyles.fundMohu1} />
                                        </View>
                                        <View style={GlobalStyles.fundMid}>
                                            <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                                        </View>
                                        <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                            <Image source={require('../../assets/images/images/image_index_mohu.png')} style={GlobalStyles.fundMohu} />
                                        </View>
                                    </TouchableOpacity>
                                )
                                fundList.push(fundItem);
                            }
                            return (
                                <View style={GlobalStyles.fundModule}>
                                    {fundList}
                                </View>
                            );
                        }else {
                            return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
                        } 
                    }
                }
            }else if(global.user.userData.is_risk == 1){
                if(data.length > 0){
                    let fundList = [];
                    for (var i = 0; i < data.length; i++) {
                        let id = data[i].id;
                        let title = data[i].title;
                        let datum_rate = data[i].datum_rate;
                        let buy_end_day = data[i].buy_end_day;
                        let buy_end_money = data[i].buy_end_money;
                        let time_limit = data[i].time_limit;
                        let start_buy_money = data[i].start_buy_money;
                        let end_people = data[i].end_people;
                        let is_collection = data[i].is_collection;
                        // consoleLog('id', id);
                        let fundItem = (
                            <TouchableOpacity key={i} onPress={()=>{this.onPushToFundDetail('FundDetail', id, title, datum_rate, buy_end_day, buy_end_money, time_limit, start_buy_money, end_people, is_collection)}} style={GlobalStyles.fundList}>
                                <View style={[GlobalStyles.fundTop, GlobalStyles.flexRowBetween]}>
                                    <Text style={GlobalStyles.fundTitle}>{data[i].title}</Text>
                                    <Text style={GlobalStyles.fundDakuan}>截止打款{data[i].buy_end_day}天</Text>
                                </View>
                                <View style={GlobalStyles.fundMid}>
                                    <Image source={{uri: data[i].photo}} style={GlobalStyles.fundThumb} />
                                </View>
                                <View style={[GlobalStyles.fundBot, GlobalStyles.flexRowBetween]}>
                                    <View style={[GlobalStyles.fundLeft, GlobalStyles.flexColumnCenter]}>
                                        <Text style={GlobalStyles.fundLeftValue}>{data[i].datum_rate}<Text style={{fontSize: 14}}>%</Text></Text>
                                        <Text style={GlobalStyles.fundLeftKey}>业绩基准</Text>
                                    </View>
                                    <View style={[GlobalStyles.fundCenter, GlobalStyles.flexColumnCenter]}>
                                        <Text style={GlobalStyles.fundCenterValue}>{data[i].time_limit}个月</Text>
                                        <Text style={GlobalStyles.fundCenterKey}>产品期限</Text>
                                    </View>
                                    <View style={[GlobalStyles.fundRight, GlobalStyles.flexColumnCenter]}>
                                        <Text style={GlobalStyles.fundRightValue}>{data[i].buy_end_money}</Text>
                                        <Text style={GlobalStyles.fundRightKey}>剩余额度</Text>
                                    </View>
                                </View>
                            </TouchableOpacity>
                        )
                        fundList.push(fundItem);
                    }
                    return (
                        <View style={GlobalStyles.fundModule}>
                            {fundList}
                        </View>
                    );
                }else {
                    return <View style={[GlobalStyles.whiteModule, {height: 360}]}></View>
                }
            }
        }
    }

    homeAbout(data) {
        let aboutList = [];
        for (var i = 0; i < data.length; i++) {
            let content_url = data[i].content_url;
            let title = data[i].title;
            let id = data[i].id;
            let aboutItem = (
                <TouchableOpacity key={i} onPress={() => {this.toWebview(title, content_url, 'NewsWebDetail', id)}} style={[GlobalStyles.newsList, GlobalStyles.flexRowStart]}>
                    <View style={GlobalStyles.newsLeft}>
                        <Image source={{ uri: data[i].photo}} style={GlobalStyles.newsThumb} />
                    </View>
                    <View style={[GlobalStyles.newsRight, GlobalStyles.flexColumnBetweenStart]}>
                        <Text style={GlobalStyles.newsTitle}>{data[i].title}</Text>
                        <Text style={GlobalStyles.newsDesc}>{data[i].remark}</Text>
                        <View style={[GlobalStyles.newsInfo, GlobalStyles.flexRowBetween]}>
                            <Text style={GlobalStyles.newsDate}>{data[i].data}</Text>
                            <View style={[GlobalStyles.newsClick, GlobalStyles.flexRowStart]}>
                                <Text style={GlobalStyles.newsClickNum}>{data[i].views}</Text>
                                <Text style={GlobalStyles.newsClickText}>阅读</Text>
                            </View>
                        </View>
                    </View>
                </TouchableOpacity>
            )
            aboutList.push(aboutItem);
        }
        if(this.state.videoSource == ''){
            return (
                <View>
                    <TouchableOpacity onPress={() => {this.videoPlay()}} style={[GlobalStyles.video, {position: 'relative'}]}>
                        <View style={styles.backgroundVideo}></View>
                        {this.state.isPlay ? null :
                        <View style={styles.play}>
                            <Image source={require('../../assets/images/icons/icon_play.png')} style={styles.playico} />
                        </View> }
                    </TouchableOpacity>

                    <View style={GlobalStyles.newsModule}>
                        {aboutList}
                    </View>
                </View>
            )
        }else{
            return (
                <View>
                    <TouchableOpacity onPress={() => {this.videoPlay()}} style={[styles.video, {backgroundColor: '#000', position: 'relative'}]}>
                       <Video
                          repeat
                          paused={this.state.isPlay ? false : true}
                          rate={this.state.isPlay ? 1 : 0}
                          resizeMode='cover'
                          source={{uri: this.state.videoSource}}
                          playInBackground={false}
                          style={styles.backgroundVideo}
                        />
                        {this.state.isPlay ? null :
                        <View style={styles.play}>
                            <Image source={require('../../assets/images/icons/icon_play.png')} style={styles.playico} />
                        </View> }
                    </TouchableOpacity>

                    <View style={GlobalStyles.newsModule}>
                        {aboutList}
                    </View>
                </View>
            )
        }
        
            
    }


    homeInvest(data) {
        let investList = [];
        for (var i = 0; i < data.length; i++) {
            let content_url = data[i].content_url;
            let title = data[i].title;
            let id = data[i].id;
            let investItem = (
                <TouchableOpacity key={i} onPress={() => {this.toWebview(title, content_url, 'NewsWebDetail', id)}} style={[GlobalStyles.newsList, GlobalStyles.flexRowStart]}>
                    <View style={GlobalStyles.newsLeft}>
                        <Image source={{ uri: data[i].photo}} style={GlobalStyles.newsThumb} />
                    </View>
                    <View style={[GlobalStyles.newsRight, GlobalStyles.flexColumnBetweenStart]}>
                        <Text style={GlobalStyles.newsTitle}>{data[i].title}</Text>
                        <Text style={GlobalStyles.newsDesc}>{data[i].remark}</Text>
                        <View style={[GlobalStyles.newsInfo, GlobalStyles.flexRowBetween]}>
                            <Text style={GlobalStyles.newsDate}>{data[i].data}</Text>
                            <View style={[GlobalStyles.newsClick, GlobalStyles.flexRowStart]}>
                                <Text style={GlobalStyles.newsClickNum}>{data[i].views}</Text>
                                <Text style={GlobalStyles.newsClickText}>阅读</Text>
                            </View>
                        </View>
                    </View>
                </TouchableOpacity>
            )
            investList.push(investItem);
        }
        return (
            <View style={GlobalStyles.newsModule}>
                {investList}
            </View>
        )
            
    }

    _renderRefreshLoading = () => {
        return (
            <RefreshControl
                tintColor={'#a4aab3'}
                titleColor={'#a4aab3'}
                title={'Loading。。。'}
                onRefresh={this._onRefresh}
                refreshing={this.state.isRefreshing}
              />
        );
    };

    _loadLocalStatus = async () => {
        try {
            const showPrivacyPolicy = await storage.load({key: Constants.SHOW_PRIVACY_POLICY});
            console.log('showPrivacyPolicy------------->', showPrivacyPolicy);
            if (showPrivacyPolicy) {
                this._requestPrivacyPolicy(false);
            }
        } catch (e) {
            console.log('e------------->', e)
            this._requestPrivacyPolicy(true);
        }
    }

    // 隐私政策弹窗
    _requestPrivacyPolicy = async (showPrivacyPolicy = false) => {
            if (showPrivacyPolicy) {
                let url = ServicesApi.index_get_agree;
                let data = {};
                const result = await Services.post(url, data, true);
                if (result.code === StatusCode.SUCCESS_CODE) {
                    this.setState({
                        mobile: result.data.mobile,
                        user_services_link: result.data.user_services_link,
                        privacy_policy_link: result.data.privacy_policy_link,
                        user_services_title: result.data.user_services_title,
                        privacy_policy_title: result.data.privacy_policy_title,
                    }, () => this._showPrivacyPolicy());
                }
            }
    };

    // 拨打电话
    _onMakeCall = (mobile) => {
        Linking.openURL('tel:' + mobile).catch(e => console.log('e---->', e));
    };

    // 页面跳转
    _onPressToNavigate = (pageTitle, component, params) => {
        const { navigate } = this.props.navigation;
        AlertManager.hide();
        console.log('params------------->', params)
        navigate(component, {
            ...params,
            onCallBack: () => this._showPrivacyPolicy(),
        })
    };

    _showPrivacyPolicy = async () => {
        let {appname, powerby, user_services_title, user_services_link, privacy_policy_title, privacy_policy_link, mobile} = this.state;
        console.log('this.state------------->', this.state)
        let detail = (
            <View style={styles.messageView}>
                <Text style={styles.messageText}>
                    感谢您下载并使用{appname},为向您提供更好的服务，可能会收集您的个人信息。我们将根据您的意愿和相关法律，严格保管并审慎使用这些信息。请您在使用前点击阅读
                    <Text
                        style={[styles.powerbyItemCur]}
                        onPress={() => {this._onPressToNavigate(user_services_title, 'WebViewPage', {title: user_services_title, link:  user_services_link})}}
                    >{user_services_title}</Text>
                    <Text style={[styles.powerbyItemCur]}>及</Text>
                    <Text
                        style={[styles.powerbyItem, styles.powerbyItemCur]}
                        onPress={() => {this._onPressToNavigate(privacy_policy_title, 'WebViewPage', {title: privacy_policy_title, link:  privacy_policy_link})}}
                    >{privacy_policy_title}</Text>
                    如果同意，请点击下方“同意”按钮开启使用{appname}。
                    {/* 阅读过程中，如有疑问，可联系我们的客服热线咨询
                    <Text style={styles.textStyle} onPress={() => this._onMakeCall(mobile)}>{mobile}</Text> */}
                </Text>
            </View>
        );
        let params = {
            detail,
            title: '温馨提示',
            actions: [
                { title: '不同意', onPress: () => ExitAppManager.exitApp()},
                {
                    title: '同意',
                    titleStyle: styles.powerbyItemCur,
                    onPress: () => {
                        storage.save({
                            key: Constants.SHOW_PRIVACY_POLICY,
                            data: true
                        });
                        AlertManager.hide();
                    },
                },
                
            ]
        };

        let option = {
            modal: true,
            onCloseRequest: null,
        };
        AlertManager.show(params, option);
    };
    

    render(){
        let {isRefreshing} = this.state;
        return (
            <View style={styles.container}>
                <ScrollView
                    refreshControl={this._renderRefreshLoading()}
                >
                    <BannerView bannerData={this.state.banner} {...this.props} />

                    <TouchableOpacity onPress={() => {this.toWebview(this.state.notice.title, this.state.notice.notice_url, 'NewsWebDetail', this.state.notice.id)}} style={[styles.gonggao, GlobalStyles.flexRowStart]}>
                        <Image source={require('../../assets/images/icons/icon_gonggao.png')} style={styles.gonggaoimg} />
                        <Text style={styles.gonggaotext}>{this.state.notice.title}</Text>
                    </TouchableOpacity>
                    
                    <View style={GlobalStyles.whiteModule}>
                        <View style={[GlobalStyles.titleModule,GlobalStyles.flexRowBetween]}>
                            <View style={[GlobalStyles.titleLeft, GlobalStyles.flexRowStart]}>
                                <Image source={require('../../assets/images/icons/icon_index_jijinjingxuan.png')} style={GlobalStyles.titleIcon} />
                                <Text style={GlobalStyles.titleText}>基金精选</Text>
                            </View>
                            <TouchableOpacity
                                onPress={()=>{
                                    this.onPushNavigator('Fund')
                                }}
                                style={[GlobalStyles.titleRight, GlobalStyles.flexRowStart]}
                            >
                                <Text style={GlobalStyles.titleMoreText}>更多</Text>
                                <Image source={require('../../assets/images/icons/icon_index_more.png')} style={GlobalStyles.titleMoreIcon} />
                            </TouchableOpacity>
                        </View>
                        {this.homeFund(this.state.fund)}
                    </View>

                    <View style={GlobalStyles.whiteModule}>
                        <View style={[GlobalStyles.titleModule,GlobalStyles.flexRowBetween]}>
                            <View style={[GlobalStyles.titleLeft, GlobalStyles.flexRowStart]}>
                                <Image source={require('../../assets/images/icons/icon_index_zoujinwomen.png')} style={GlobalStyles.titleIcon} />
                                <Text style={GlobalStyles.titleText}>走进我们</Text>
                            </View>
                            <TouchableOpacity onPress={()=>{this.onPushNavigator('About')}} style={[GlobalStyles.titleRight, GlobalStyles.flexRowStart]}>
                                <Text style={GlobalStyles.titleMoreText}>更多</Text>
                                <Image source={require('../../assets/images/icons/icon_index_more.png')} style={GlobalStyles.titleMoreIcon} />
                            </TouchableOpacity>
                        </View>
                        {this.homeAbout(this.state.about_us)}
                    </View>

                    <View style={GlobalStyles.whiteModule}>
                        <View style={[GlobalStyles.titleModule,GlobalStyles.flexRowBetween]}>
                            <View style={[GlobalStyles.titleLeft, GlobalStyles.flexRowStart]}>
                                <Image source={require('../../assets/images/icons/icon_index_touzishijie.png')} style={GlobalStyles.titleIcon} />
                                <Text style={GlobalStyles.titleText}>投资视界</Text>
                            </View>
                            <TouchableOpacity onPress={()=>{this.onPushNavigator('Invest')}} style={[GlobalStyles.titleRight, GlobalStyles.flexRowStart]}>
                                <Text style={GlobalStyles.titleMoreText}>更多</Text>
                                <Image source={require('../../assets/images/icons/icon_index_more.png')} style={GlobalStyles.titleMoreIcon} />
                            </TouchableOpacity>
                        </View>
                        {this.homeInvest(this.state.article)}
                    </View>
                </ScrollView>
            </View>
        );
    }

}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: GlobalStyles.bgColor,
    },
    webContainer: {
        width: GlobalStyles.width,
        height: GlobalStyles.height,
        flex: 1,
        backgroundColor: '#fff',
        marginTop: __IOS__ ? -15 : 0,
    },
    gonggao: {
        backgroundColor: '#fff',
        height: 45,
        paddingLeft: 15,
        paddingRight: 15,
    },
    gonggaoimg: {
        width: 19,
        height: 19*60/64,
        marginRight: 10
    },
    gonggaotext: {
        flex: 1,
        color: '#888888',
        fontSize: 15,
        width: (GlobalStyles.width - 30) - 19 - 10
    },
    fundLogin: {
        width: GlobalStyles.width,
        flex: 1,
        backgroundColor: '#fff'
    },
    fundLoginImg: {
        width: GlobalStyles.width,
        height: GlobalStyles.width*860/660,
    },
    submitbot: {
        position: 'absolute',
        bottom: 0,
        width: GlobalStyles.width - 30,
        borderRadius: 0,
        height: 42        
    },
    backgroundVideo: {
        width: GlobalStyles.width - 30,
        height: (GlobalStyles.width - 30)*460/800,
        backgroundColor: '#000',
        borderRadius: 3
    },
    play: {
        position: 'absolute',
        top: (GlobalStyles.width - 30)*460/800/2,
        left: (GlobalStyles.width - 30)/2,
        marginLeft: -35,
        marginTop: -35,
        width: 70,
        height: 70
    },
    playico: {
        width: 70,
        height: 70,
    },
    video: {
        margin: 15,
        marginBottom: 5,
        borderRadius: 3
    },
    modalpic: {
        width: GlobalStyles.width,
        height: GlobalStyles.height
    },
    modalCeng: {
        position: 'absolute',
        top: 0,
        left: 0,
        width: GlobalStyles.width,
        height: GlobalStyles.height,
    },
    botBar: {
        height: 54,
        backgroundColor: '#fff',
        display: 'flex',
        flexDirection: 'row',
        justifyContent: 'center',
        alignItems: 'center',
        borderTopColor: '#ececec',
        borderTopWidth: 1,

    },
    botLeft: {
        flex: 1,
        display: 'flex',
        flexDirection: 'column',
        justifyContent: 'center',
        alignItems: 'center'
    },
    botLeftIco: {
        height: 24,

    },
    botLeftText: {
        fontSize: 13,
        color: '#666',
        height: 20,
        lineHeight: 20,
    },
    botRight: {
        flex: 2.5,
        backgroundColor: GlobalStyles.themeColor,
        height: 54,
        justifyContent: 'center',
        alignItems: 'center',

    },
    botRightText: {
        color: '#fff',
        fontSize: 18,
        fontWeight: 'bold'
    },

    messageView: {
        marginTop: 15,
        paddingVertical: 10,
        paddingHorizontal: 15,
    },
    messageText: {
        fontSize: 13,
        color: '#666',
        lineHeight: 18,
        textAlign: 'justify',
    },
    powerbyItemCur: {
        color: '#539ff3',
    },
});